import React, { Component } from 'react'
import { Button, Table, Modal, Row, Col, Popconfirm, Input, Form, message } from 'antd';
import { connect } from 'react-redux';
import { findExaming, findExamingByNumber, getResourceInfo, getResourceTableInfo} from '../../../api/resourceCategory/resourceCategory'
import { actionCreators} from './store'
// import { actionCreators } from './store';
import CommonView from '../commonView'
class AnalyseList extends Component {
  constructor() {
    super()
    this.state = {
      dataSource: [],
      showView: false,
      passDataSource: [],
      passBaseInfo: {},
      paginationNo: {
        pageSize: 10,
        defaultCurrent:1,
        current:1,
      },
      columns : [
        {
          title:'报送时间', key:'create_time', dataIndex:'create_time',
        },
        {
          title: '操作', dataIndex: 'action', key: 'action', width: 220,
          render: (text, record) => <Button size="small" type="link" onClick={() => this.handleView(record)}>查看</Button>
        }
      ]
    }


  }

  handleView = record => {
    let requestData = {resourceId: record.resource_id,}
    getResourceInfo(requestData).then(res => {
      if(res.data.metaData.code === 'success') {
        this.setState({passBaseInfo: res.data.data})
        this.props.setFormInitialData(res.data.data)
      }
    })
    getResourceTableInfo(requestData).then(res => {
      if(res.data.metaData.code === 'success') {
        this.setState({passDataSource: res.data.data, showView: true})
      }
    })
  }

  getExaming = (number, page, pageSize) => {
    findExaming({pageNum: page, pageSize: pageSize, number}).then(res => {
      if(res.data.metaData.code === 'success') {
        const paginationNo = this.state.paginationNo
        paginationNo.total = res.data.data.total
        paginationNo.current = res.data.data.pageNum
        this.setState({dataSource: res.data.data.list})
      }
    })
  }

  componentWillMount() {
    console.log('this.props.baseCOlumns', this.props.baseColumns)
    this.setState({
      columns: [...this.props.baseColumns ,...this.state.columns]
    })
    this.getExaming('01010000', 1,10)
  }

  showModal = () => {
    this.setState({
      show: true
    })
  }
  handleOk = e => {
    this.setState({
      show: false
    })
  }

  handleCancel = e => {
    this.setState({
      show: false
    })
  }

  //删除配置
  handleDeleteClick(code) {
    // this.props.deleteAnalyseTask({code: code})
  }
  render() {
    const  { curRecord, columns, dataSource, passBaseInfo, passDataSource  } = this.state
    return (
      <div>
        <Table
          size="small" loading={this.state.loading}
          dataSource={this.state.dataSource}
          columns={columns} bordered rowKey={record => record.taskId} 
          style={{ padding: 20 }}
          pagination={this.state.paginationNo} />
        <Modal title={'查看'} visible={this.state.showView}  onOk={this.handleLogOk} onCancel={e => this.setState({showView: false})} closable={true}  destroyOnClose
          bodyStyle={{backgroundColor:'#f0f3f6',overflow:'auto',height:540}} width={700}
          footer={[<Button size='small' type='primary' onClick={e => this.setState({showView: false})}>确认</Button>]}>
          <CommonView dataSource={passDataSource} infos={passBaseInfo} />

        </Modal>
      </div>
    )
  }
}



const mapState = (state) => {
  // const { taskList} = state.DataAnalyseReducer;
  // const obj = {taskList}
  // console.log('质量剖析',obj)
  // return {
  //    taskList
  // }
}

const mapDispatch = (dispatch) => {
  return {
    deleteAnalyseTask(data) {
    },
    setFormInitialData(data) {
      console.log('data', data)
      dispatch(actionCreators.setFormInitialData(data))
    },
  }
} 
export default connect(mapState, mapDispatch)(AnalyseList)


